/**
 * 
 */
package genealogy.deprecated.datamodel.pedigree.visitors;

import java.io.File;

import genealogy.deprecated.datamodel.pedigree.Date;
import genealogy.deprecated.datamodel.pedigree.Gender;
import genealogy.deprecated.datamodel.pedigree.Individual;
import genealogy.deprecated.datamodel.pedigree.LifeEvent;
import genealogy.deprecated.datamodel.pedigree.Location;
import genealogy.deprecated.datamodel.pedigree.Name;
import genealogy.deprecated.datamodel.pedigree.RelationshipType;
import genealogy.depricated.loaders.FhdPairsLoader;

/**
 * @author Steve
 * @invariant
 */
@Deprecated
public class PedigreeToConsoleVisitor implements IPedigreeVisitor {

	private StringBuilder builder;

	private int tabs;

	public PedigreeToConsoleVisitor() {
		tabs = -1;
		builder = new StringBuilder();
	}

	private void reset() {
		tabs = -1;
		builder = new StringBuilder();
	}

	public String toString() {
		return builder.toString();
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see genealogy.datamodel.pedigree.visitors.IPedigreeVisitor#endVisit()
	 */
	public void endVisit() {
		tabs--;
	}

	private void appendTabs() {
		for (int i = 0; i < tabs; i++)
		{
			builder.append("\t");
		}
	}

	private void addLine(String line) {
		appendTabs();
		builder.append(line + "\n");
		tabs++;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see genealogy.datamodel.pedigree.visitors.IPedigreeVisitor#visit(genealogy.datamodel.pedigree.Date)
	 */
	public void visit(Date date) {
		addLine(date.toString());
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see genealogy.datamodel.pedigree.visitors.IPedigreeVisitor#visit(genealogy.datamodel.pedigree.Event)
	 */
	public void visit(LifeEvent event) {
		addLine(event.getEventName());
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see genealogy.datamodel.pedigree.visitors.IPedigreeVisitor#visit(genealogy.datamodel.pedigree.Gender)
	 */
	public void visit(Gender gender) {
		addLine("Gender: " + gender.toString());
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see genealogy.datamodel.pedigree.visitors.IPedigreeVisitor#visit(genealogy.datamodel.pedigree.Location)
	 */
	public void visit(Location location) {
		addLine("Location: " + location.toString());
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see genealogy.datamodel.pedigree.visitors.IPedigreeVisitor#visit(genealogy.datamodel.pedigree.Name)
	 */
	public void visit(Name name) {
		addLine(name.toString());
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see genealogy.datamodel.pedigree.visitors.IPedigreeVisitor#visit(genealogy.datamodel.pedigree.RelationshipType)
	 */
	public void visit(RelationshipType type) {
		addLine(type.toString());
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see genealogy.datamodel.pedigree.visitors.IPedigreeVisitor#visit(genealogy.datamodel.pedigree.Individual)
	 */
	public void visit(Individual individual) {
		tabs++;
	}

	public static void main(String[] args) {
		PedigreeToConsoleVisitor consoleWriter = new PedigreeToConsoleVisitor();

		File file = new File(args[0]);
		FhdPairsLoader loader = new FhdPairsLoader();
		System.out.print("loading file " + file + " ... ");
		loader.load(file);
		System.out.println("done");

		for (int i = 1; i < 5; i++)
		{
			loader.getPair(i).getPedigreeA().accept(consoleWriter);
			System.out.println(consoleWriter);
			consoleWriter.reset();
			loader.getPair(i).getPedigreeB().accept(consoleWriter);
			System.out.println(consoleWriter);
			consoleWriter.reset();
			System.out.println("*****************************************");
		}
	}
}
